package TCP.moreClient;
import java.io.InputStream;
import java.net.Socket;

public class ServerReader extends  Thread{
    private Socket socket;
    public ServerReader(Socket socket)
    {
        this.socket = socket;
    }
    @Override
    public void run(){
        try{
            InputStream is = socket.getInputStream();
            while (true){
                byte[] bytes = new byte[1024];
                int len = is.read(bytes);
                String msg = new String(bytes,0,len);
                System.out.print(socket.getInetAddress().getHostName()+"说：");
                System.out.println(msg);
                if (msg.equals("886")){
                    System.out.println("=====服务器退出=====");
                    is.close();
                    socket.close();
                    break;
                }
                socket.getOutputStream().write("收到".getBytes());
            }
        }catch (Exception e){
            System.out.println("一个客户端下线了:"+socket.getInetAddress().getHostAddress());
        }
    }
}
